<#assign startStr="{"/>
<#assign endStr="}"/>
<#list domains as domain> 
<ibatis>   
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
	"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${coder.packageName}.dao.${domain.entityName?cap_first}Dao">
<sql id="limit">
	<if test="startRow != null and endRow !=null">limit #${startStr}startRow${endStr},#${startStr}endRow${endStr}</if>
</sql>	
<sql id="orderCondition">
	<if test="orderColumn != null and orderColumn != ''">ORDER BY $${startStr}orderColumn${endStr} </if>
</sql>

<sql id="Condition">
	<where>
		<#list domain.properties as property>
		<if test="${property.name} != null "><![CDATA[AND ${property.column} =#${startStr}${property.name}${endStr}]]></if>		
		</#list>			
	</where>
</sql>
<sql id="columns">
	<#assign index=0/>
	<#assign currentsize=domain.properties?size-1/>
	<#list domain.properties as property>${property.column} as ${property.name} <#if index != currentsize >,</#if><#assign index=index+1/></#list>
</sql>
	<#assign index=0/>
<insert id="insert" parameterType="${domain.entityName}">
  	insert into ${domain.tableName}
  	(<#list domain.properties as property>${property.column}<#if index != currentsize >,</#if><#assign index=index+1/></#list>)
  	values
  	(<#assign index=0/><#list domain.properties as property>#${startStr}${property.name}${endStr}<#if index != currentsize >,</#if><#assign index=index+1/></#list>)
 	<selectKey keyProperty="id" resultType="long" order="AFTER">
        select last_insert_id()
    </selectKey>
</insert>

<delete id="del" parameterType="long">  
    update  ${domain.tableName} set del_status=2,update_Time=now() where id = #${startStr}id${endStr}
</delete> 
  
<update id="update" parameterType="${domain.entityName}">
	update ${domain.tableName} 
  	<set>
  		<#assign idColumn=''/>
  		<#assign idProperty=''/><#assign index=0/>
  		<#list domain.properties as property>
  		<#if property.identity == true>
  			<#assign idColumn=property.column/><#assign idProperty=property.name/>
  		<#else>  			
  			<#if property.type.type == "String">
  				<if test="${property.name} != null "><![CDATA[ ${property.column} =#${startStr}${property.name}${endStr},]]></if>		
  			<#else>
  				<if test="${property.name} != null "><![CDATA[ ${property.column} =#${startStr}${property.name}${endStr},]]></if>		
  			</#if>
  		</#if>		
		</#list> 
  	</set> 
    where  id=#${startStr}id${endStr}
  </update> 
  <select id="queryCount" parameterType="${domain.entityName}" resultType="int">
        select count(1) from ${domain.tableName} 
        <include refid="Condition"/>
  </select> 
  <select id="query" parameterType="${domain.entityName}" resultType="${domain.entityName}">
        select 
         <include refid="columns"/>
		from ${domain.tableName} 
        <include refid="Condition"/>
	<include refid="orderCondition"/>
        <include refid="limit"/>        
  </select> 
  </mapper>
</ibatis>
</#list> 
